
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
    debugger
    if (changeInfo.status === 'complete') {
        // 页面加载成功
        chrome.action.setBadgeText({ text: '成功' })
        chrome.action.setBadgeBackgroundColor({ color: '#4CAF50' })
        chrome.notifications.create({
            type: 'basic',
            iconUrl: 'images/icon48.png',
            title: '页面加载状态',
            message: '页面加载成功！'
        })
        debugger
        // chrome.scripting.executeScript({
        //     target: { tabId: tabId },
        //     files: ['download.js'],
        // })
    } else if (changeInfo.status === 'loading') {
        // 页面加载失败
        chrome.action.setBadgeText({ text: '失败' })
        chrome.action.setBadgeBackgroundColor({ color: '#F44336' })
        chrome.notifications.create({
            type: 'basic',
            iconUrl: 'images/icon48.png',
            title: '页面加载状态',
            message: '页面加载失败！'
        })
        // chrome.scripting.executeScript({
        //     target: { tabId: tabId },
        //     files: ['content.js'],
        //     // func: handlePageLoadSuccess
        // })
        debugger
        // getLocalStorage(tabId)
    }
})

// function getLocalStorage (tabId) {
//     chrome.tabs.sendMessage(tabId, { action: "getLocalStorage" }, function (response) {
//         if (response && response.localStorageData) {
//             debugger
//             const localStorageData = response.localStorageData
//             console.log('LocalStorage Data:', localStorageData)
//             let pageNo = Number(localStorageData.pageNo) || 1
//             console.log('Page No:', pageNo)
//             chrome.tabs.update(tabId, { url: `http://www.8btxt.com/classtop/3-0-${pageNo}.html` })
//         } else {
//             console.log('LocalStorage Data is empty or not found')
//             debugger
//             // chrome.tabs.reload(tabId)
//         }
//     })
// }